package com.game.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.game.dao.IGameRoundDao;
import com.game.pojo.GameRound;
/**
 * 游戏回合dao的实现类
 * @author Administrator
 *
 */
public class GameRoundDao implements IGameRoundDao {
	//注入持久化上下文
	@PersistenceContext(unitName="mms_persistence_guessnumber")
	private EntityManager entityManager;
	
	/**
	 * 保存游戏回合信息
	 */
	@Override
	public void saveGameRound(GameRound gameRound) {
		entityManager.persist(gameRound);
		
	}
	
	/**
	 * 根据游戏id获取游戏回合集合
	 */
	@Override
	public List<GameRound> getGameRoundsByGid(int gid) {
		List<GameRound> resultList = entityManager.createQuery("select gr from GameRound gr join gr.game g where g.gameId = :gameId")
						.setParameter("gameId", gid).getResultList();
		
		
		return resultList;
	}
	
	
}
